package com.education.user.controller.login;


import com.education.common.pojo.AjaxResult;
import com.education.common.utils.StringUtils;
import com.education.user.pojo.LoginUser;
import com.education.user.pojo.User;
import com.education.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.TreeMap;

@RestController
@RequestMapping("/login")
public class LoginUserController {

    @Autowired
    private UserService userService;

    //密码登陆
    @PostMapping("/landing")
    public AjaxResult login(@RequestBody LoginUser loginUser) {
        if (StringUtils.isEmpty(loginUser.getUserName())) return AjaxResult.error("请输入手机号");
        if (StringUtils.isEmpty(loginUser.getPassWord())) return AjaxResult.error("请输入密码");
        List<User> userList = userService.findByPhone(loginUser.getUserName());
        if (StringUtils.isEmpty(userList)) return AjaxResult.error("用户不存在");
        if (StringUtils.isNotPassWord(loginUser.getPassWord(), userList.get(0).getSysPassword()))
            return AjaxResult.error("密码错误");
        return AjaxResult.success(userList.get(0));
    }
}
